package net.sourceforge.web.chartjs;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Chart2D{
	public static final String[] CHARTS={"line", "bar", "radar", "doughnut", "pie", "polar", " area", "bubble", "scatter"};
	public static final Set<String> SUPPRTED_SET=new HashSet<>();
	static{
		for(String c:CHARTS){
			SUPPRTED_SET.add(c);
		}
	}
	
	private String type;
	private ChartOptions options;
	private DatasetCollection data;
	
	public Chart2D(String type, String title, String summary, String group) {
		super();
		if(!SUPPRTED_SET.contains(type)){
			throw new java.lang.UnsupportedOperationException(type+" is not supported");
		}
		
		ChartTitle chartTitle=new ChartTitle();
		chartTitle.setDisplay(true);
		chartTitle.setText(title);
		
		this.options.setTitle(title);
		data=new DatasetCollection();
	}
	
	public void setXArray(List<Object> xarray){
		if("scatter".equals(this.type)){
			throw new java.lang.UnsupportedOperationException("scatter does not support setXArray, only support add sparse truples");
		}
		data.setLabels(xarray);
	}
		
	public void addYSeries(String name, List<Object> xarray){
		data.addSeries(name, xarray);
	}
	
	public void setValueAxisTitle(String t){
		options.setValueAxisTitle(t);
	}
	
	public void setDomainAxisTitle(String t){
		options.setDomainAxisTitle(t);
	}
	
	public void setBorderColor(int index, String color){
		data.setBorderColor(index, color);
	}
	
	public void setDotColor(int index, String color){
		data.setDotColor(index, color);
	}
	
	public void setShowLine(int index, boolean showLine){
		data.setShowLine(index, showLine);
	}
}
